// home的小仓库

// 引入发送请求的函数
import { reqCategoryList, reqGetBannrList, reqFloorList } from "@/api";

// 仓库存储数据的地方
const state = {
  categoryList: [],
  bannerList: [],
  floorList: []
}
// 修改state数据
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  FLOORLIST(state, floorList) {
    state.floorList = floorList
  }
}
// 处理业务,可以书写自己的业务逻辑
const actions = {
  // 通过API里面的接口函数调用,向服务器发请求,获取服务器数据

  // 获取三级联动商品分类数据
  async categoryList({ commit }) {
    let result = await reqCategoryList()
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data) //数据提交给mutations处理
    }
  },
  // 获取首页轮播图数据
  async getBannerList({ commit }) {
    let result = await reqGetBannrList()
    if (result.code == 200) {
      commit('BANNERLIST', result.data) //数据提交给mutations处理
    }
  },
  // 获取floor数据
  async getFloorList({ commit }) {
    let result = await reqFloorList()
    if (result.code == 200) {
      commit('FLOORLIST', result.data)
    }
  }
}
// 计算属性,用于简化仓库数据,获取数据更加方便
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}

